package com.suntianci.stock.controller;

import com.suntianci.stock.pojo.domain.PermissionDomain;
import com.suntianci.stock.pojo.domain.PermissionInfo4AddPermissionDomain;
import com.suntianci.stock.pojo.entity.SysPermission;
import com.suntianci.stock.service.PermissionService;
import com.suntianci.stock.vo.req.AddPermissionReqVo;
import com.suntianci.stock.vo.req.UpdatePermissionReqVo;
import com.suntianci.stock.vo.resp.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName PermissionController
 * @Author 孙天赐
 * @Date 2025/1/11 16:17
 * @Description TODO: 权限相关接口控制器
 */
@RestController
@Api(tags = "权限相关接口控制器")
@RequestMapping("/api")
public class PermissionController {

    @Autowired
    private PermissionService permissionService;

    /**
     * 查询所有权限集合
     * @return
     */
    @ApiOperation(value = "查询所有权限集合", notes = "查询所有权限集合", httpMethod = "GET")
    @GetMapping("/permissions")
    private R<List<SysPermission>> getAllPermission(){
        return permissionService.getAllPermission();
    }

    /**
     * 树状结构查询权限集合
     * @return
     */
    @ApiOperation(value = "树状结构查询权限集合", notes = "树状结构查询权限集合", httpMethod = "GET")
    @GetMapping("/permissions/tree/all")
    public R<List<PermissionDomain>> getAllPermission2Tree(){
        return permissionService.getAllPermission2Tree();
    }

    /**
     * 添加权限时回显权限树,仅仅显示目录和菜单
     * @return
     */
    @ApiOperation(value = "添加权限时回显权限树，仅仅显示目录和菜单", notes = "添加权限时回显权限树，仅仅显示目录和菜单", httpMethod = "GET")
    @GetMapping("/permissions/tree")
    public R<List<PermissionInfo4AddPermissionDomain>> getAllPermissionWithLevel(){
        return permissionService.getAllPermissionWithLevel();
    }

    /**
     * 添加权限
     * @param addPermissionReqVo
     * @return
     */
    @ApiOperation(value = "添加权限", notes = "添加权限", httpMethod = "POST")
    @ApiImplicitParam(name = "addPermissionReqVo", value = "添加权限请求实体Vo类", dataType = "AddPermissionReqVo", required = true, type = "query")
    @PostMapping("/permission")
    public R<Void> addPermission(@RequestBody AddPermissionReqVo addPermissionReqVo){
        return permissionService.addPermission(addPermissionReqVo);
    }

    /**
     * 修改权限信息
     * @param updatePermissionReqVo
     * @return
     */
    @ApiOperation(value = "修改权限信息", notes = "修改权限信息", httpMethod = "PUT")
    @ApiImplicitParam(name = "updatePermissionReqVo", value = "修改权限请求实体Vo类", dataType = "UpdatePermissionReqVo", required = true, type = "query")
    @PutMapping("/permission")
    public R<Void> updatePermission(@RequestBody UpdatePermissionReqVo updatePermissionReqVo){
        return permissionService.updatePermission(updatePermissionReqVo);
    }

    /**
     * 根据权限id删除权限
     * @param permissionId
     * @return
     */
    @ApiOperation(value = "根据权限id删除权限", notes = "根据权限id删除权限", httpMethod = "DELETE")
    @ApiImplicitParam(name = "permissionId", value = "权限id", dataType = "string", required = true, type = "path")
    @DeleteMapping("/permission/{permissionId}")
    public R<Void> deletePermission(@PathVariable String permissionId){
        return permissionService.deletePermission(permissionId);
    }
}
